package cn.cdutetc.foxwatch.controller.tripartite;

import cn.cdutetc.foxwatch.exception.MyException;
import cn.cdutetc.foxwatch.pojo.Result;
import cn.cdutetc.foxwatch.pojo.UserInfo;
import cn.cdutetc.foxwatch.pojo.tripartite.PhonePojo;
import cn.cdutetc.foxwatch.serveice.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/tripartite")
public class Tripartite {
    @Autowired
    private UserInfoService userInfoService;


    /*
    暂未接通
    */
    @GetMapping("/weixin/{code}")
    public Result<String> WeiXin(@RequestBody UserInfo user, @PathVariable("code") String code) throws MyException {
        String token = userInfoService.weixinLogin(user, code);
        return Result.success(token);
    }

    @PostMapping("/phone")
    public Result<String> Phone(@RequestBody PhonePojo phone) throws MyException {
        String token = userInfoService.phoneLogin(phone);
        return Result.success(token);
    }

    @PostMapping(value = {"/email{code}"})
    public Result<String> emailLogin(@RequestBody UserInfo user, @PathVariable(value = "code", required = false) String code) throws MyException {
        String token = userInfoService.emailLogin(user, code);
        return Result.success(token);
    }
}
